//
//  TimeUtils.m
//  Test
//
//  Created by 孙叔康 on 2022/7/28.
//

#import "TimeUtils.h"

@implementation TimeUtils

#pragma mark - 给个String对象字符串 @"yyyy-MM-dd HH:mm:ss"  返回对应的时间Str (例2018-05-31 08:00:00)
+ (NSString *)dateStringWithStr:(NSString*)dateStr defaultdateFormat:(NSString*)defaultdateFormat  NewDateFormat:(NSString *)dateFormat{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"]];
    
    dateFormatter.dateFormat = defaultdateFormat;
    NSDate *date = [dateFormatter dateFromString:dateStr];
    
    //再设置新的格式，转为新的字符串
    [dateFormatter setDateFormat:dateFormat];
    NSString *timeStr = [dateFormatter stringFromDate:date];
    return timeStr ? timeStr : @"";
}



+ (NSDate *)timeDateWithString:(NSString *)timeString format:(NSString *)format{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"]];
    
    dateFormatter.dateFormat = format;
    NSDate *date = [dateFormatter dateFromString:timeString];
    return date;
}

@end
